package com.hsh.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hsh.bean.Sleep;
import com.hsh.dao.SleepMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SleepService {

    @Resource
    private SleepMapper sleepMapper;

    public Integer insert(Sleep sleep){
        System.out.println("sleep---service--insert"+ sleep);
        return sleepMapper.insert(sleep);
    }

    public Integer delete(Integer sid){
        return sleepMapper.deleteByPrimaryKey(sid);
    }

    public Integer update(Sleep sleep){
        return sleepMapper.updateByPrimaryKey(sleep);
    }

    public Sleep findById(Integer sid){
        return sleepMapper.findById(sid);
    }

    public PageInfo<Sleep> findSleepByPage(Sleep sleep, Integer pageNum, Integer pageSize){
        return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(
                ()->{sleepMapper.findBySleep(sleep);});
    }

    public Integer findByDateAndUid(Sleep sleep){
        return sleepMapper.findByDateAndUid(sleep);
    }
}
